package com.spic.business.ioc.service.impl;

import com.spic.business.ioc.domain.IocPmTwoPointFive;
import com.spic.business.ioc.mapper.IocPmTwoPointFiveMapper;
import com.spic.business.ioc.service.IIocPmTwoPointFiveService;
import com.spic.common.core.domain.R;
import com.spic.common.core.utils.StringUtils;
import com.spic.common.core.utils.UUIDUtil;
import com.spic.system.api.RemoteDictDataService;
import com.spic.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * PM2.5达标情况IOCService业务层处理
 *
 * @author spic
 * @date 2022-04-14
 */
@Service
public class IocPmTwoPointFiveServiceImpl implements IIocPmTwoPointFiveService
{
    @Autowired
    private IocPmTwoPointFiveMapper iocPmTwoPointFiveMapper;
    @Autowired
    private RemoteDictDataService remoteDictDataService;
    /**
     * 查询PM2.5达标情况IOC
     *
     * @param id PM2.5达标情况IOC主键
     * @return PM2.5达标情况IOC
     */
    @Override
    public IocPmTwoPointFive selectIocPmTwoPointFiveById(String id)
    {
        return iocPmTwoPointFiveMapper.selectIocPmTwoPointFiveById(id);
    }

    /**
     * 查询PM2.5达标情况IOC列表
     *
     * @param iocPmTwoPointFive PM2.5达标情况IOC
     * @return PM2.5达标情况IOC
     */
    @Override
    public List<IocPmTwoPointFive> selectIocPmTwoPointFiveList(IocPmTwoPointFive iocPmTwoPointFive)
    {
        return iocPmTwoPointFiveMapper.selectIocPmTwoPointFiveList(iocPmTwoPointFive);
    }

    /**
     * 新增PM2.5达标情况IOC
     *
     * @param iocPmTwoPointFive PM2.5达标情况IOC
     * @return 结果
     */
    @Override
    public int insertIocPmTwoPointFive(IocPmTwoPointFive iocPmTwoPointFive)
    {
        if(StringUtils.isNotEmpty(iocPmTwoPointFive.getCompliance()))
        {
            R<List<SysDictData>> monitoring_location_type = remoteDictDataService.getDictDataByDictType("compliance_type");
            List<SysDictData> dictList = monitoring_location_type.getData();

            for (SysDictData dict : dictList)
            {
                //分类列表数据
                if (dict.getDictValue().equals(iocPmTwoPointFive.getCompliance()))
                {
                    iocPmTwoPointFive.setComplianceName(dict.getDictLabel());
                    break;
                }
            }
        }
        String uuid = UUIDUtil.createUUID();
        iocPmTwoPointFive.setId(uuid);
        return iocPmTwoPointFiveMapper.insertIocPmTwoPointFive(iocPmTwoPointFive);
    }

    /**
     * 修改PM2.5达标情况IOC
     *
     * @param iocPmTwoPointFive PM2.5达标情况IOC
     * @return 结果
     */
    @Override
    public int updateIocPmTwoPointFive(IocPmTwoPointFive iocPmTwoPointFive)
    {
        if(StringUtils.isNotEmpty(iocPmTwoPointFive.getCompliance()))
        {
            R<List<SysDictData>> monitoring_location_type = remoteDictDataService.getDictDataByDictType("compliance_type");
            List<SysDictData> dictList = monitoring_location_type.getData();

            for (SysDictData dict : dictList)
            {
                //分类列表数据
                if (dict.getDictValue().equals(iocPmTwoPointFive.getCompliance()))
                {
                    iocPmTwoPointFive.setComplianceName(dict.getDictLabel());
                    break;
                }
            }
        }
        return iocPmTwoPointFiveMapper.updateIocPmTwoPointFive(iocPmTwoPointFive);
    }

    /**
     * 批量删除PM2.5达标情况IOC
     *
     * @param ids 需要删除的PM2.5达标情况IOC主键
     * @return 结果
     */
    @Override
    public int deleteIocPmTwoPointFiveByIds(String[] ids)
    {
        return iocPmTwoPointFiveMapper.deleteIocPmTwoPointFiveByIds(ids);
    }

    /**
     * 删除PM2.5达标情况IOC信息
     *
     * @param id PM2.5达标情况IOC主键
     * @return 结果
     */
    @Override
    public int deleteIocPmTwoPointFiveById(String id)
    {
        return iocPmTwoPointFiveMapper.deleteIocPmTwoPointFiveById(id);
    }

    /**
     * @return PM2.5达标情况
     */

    @Override
    public List<Map<String, Object>> getPm25()
    {
        return null;
    }
}
